using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class PlanetManager : MonoBehaviour {
	
	//星球ID.
	public int PlanetID;
	//背景物件.
	public GameObject PlanetBG;
	public GameObject LeftMenu;
	public Material[] TotolMaterial;
	public GameObject PlanetEventer;
	Dictionary<string,Material> BGMaterial;
	
	PlanetData Data;
	
	// Use this for initialization
	void Start () {
		FinishingMaterial();
		LoadPlanetData();
		LoadBG();
		PlanetEventer.SendMessage("StartEvent");
	}
	
	void FinishingMaterial()
	{
		BGMaterial = new Dictionary<string, Material>();
		foreach(Material m in TotolMaterial)
		{
			BGMaterial.Add(m.name,m);
		}
	}
	
	void LoadPlanetData(){
		if(GameData.PlanetDatas == null)
		{
			DataLoad dataLoad = new DataLoad();
			dataLoad.LoadConfig();
		}
		Data = GameData.PlanetDatas[PlanetID];
	}
	
	void OnEventFinish(){
		ShowPlane();
	}
	
	void ShowPlane(){
		if(LeftMenu.active == false)
			LeftMenu.SetActiveRecursively(true);
	}
	
	void LoadBG(){
		string BgName = Data.BgName;
		PlanetBG.GetComponent<UITexture>().material = BGMaterial[BgName];
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}
